const { getCode } = require("../../../api/api")
const { get } = require("../../../utils/utils")
const WXAPI = require("../../../api/newApi")
const WXAPIOLD = require("../../../api/api")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
    this.giveQrCode()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  //唤醒扫一扫功能
  getScancode: function() {
    var that = this;
    // 允许从相机和相册扫码
    wx.scanCode({
      success: (res) => {
        console.log(res.result)
        let parameter = res.result.split("code=")[1];
        console.log(parameter)
        let result = JSON.parse(parameter)
        console.log(result)
        console.log("扫一扫参数",result.param)
        console.log("扫一扫类型",result.type)
        if(result.type==1){
          wx.navigateTo({
            url: '/userPageA/pages/scan/information/information?param=' + result.param
          })
        }else if(result.type==2){
          wx.navigateTo({
            url: '/userPageA/pages/scan/receiving_assets/receiving_assets?param=' + result.param
          })
        }else if(result.type==4){
          this.setData({
            qrCodeUrl: result.param,
          })
          this.getParCollectionQrCodeUrl()
        }
        else{
          console.log('else')
        }
      },
      fail:(res)=>{
        console.log(res)
      }
    })
  },
  //解析二维码confirmInfo
  getParCollectionQrCodeUrl(){
   
    var data = {
      qrCodeUrl:this.data.qrCodeUrl,
      // qrCodeUrl:'https://bee.xiaodaiyan.com/pay/uQRxY%2F6Y4pbfVN4%2BbISi5WEG2fcys%2Beg9h2%2B0dfXuU8%3D',
    }
    WXAPIOLD.parCollectionQrCodeUrl(data, (res) =>{
      const data = res.result
      console.log("解析二维码",res)
      if(res.code === 200){
        var merchantId = data.merchantId
        wx.navigateTo({
          url: '/pages/pay/pay?QRmerchantId='+merchantId,
        })
      }else{
        wx.showToast({
          title: '无效收款码',
          icon: 'none'
        })
      }
    })
  },
  giveQrCode(){ //giveQrCode
    var data = {
      
    }
    WXAPI.giveQrCode(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        this.setData({
          img: res.result
        })
        wx.hideLoading()
      }
    })
  },
  back(){
    wx.reLaunch({
      // url: '/pages/assets/assets',
      url:'/pages/userMarket/userMarket'
    })
  },
  jumpzc(){ //资产选择
    wx.navigateTo({
      url: '/userPageA/pages/wallet/asset_selection/asset_selection',
    })
  },
  jumpRecord(){ //转赠记录
    wx.navigateTo({
      url: '/userPageA/pages/wallet/gift_record/gift_record',
    })
  },
})